﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace IBOBO_Controls
{
    public partial class _frmProcessBar : Form
    {
        Thread Thd;

        public _frmProcessBar(Thread _thd)
        {
            InitializeComponent();
            Thd = _thd;

            this.MouseDown += new MouseEventHandler(Control_MouseDown);
            this.MouseMove += new MouseEventHandler(Control_MouseMove);
            this.MouseUp += new MouseEventHandler(Control_MouseUp);

            foreach (Control cnt in this.Controls)
            {
                cnt.MouseDown += new MouseEventHandler(Control_MouseDown);
                cnt.MouseMove += new MouseEventHandler(Control_MouseMove);
                cnt.MouseUp += new MouseEventHandler(Control_MouseUp);
            }
        }

        bool IsDrag = false;
        int OrgX = 0, OrgY = 0;
        private void Control_MouseDown(object sender, MouseEventArgs e)
        {
            IsDrag = true;
            OrgX = e.X;
            OrgY = e.Y;
        }

        private void Control_MouseMove(object sender, MouseEventArgs e)
        {
            if (IsDrag)
            {
                this.Left += e.X - OrgX;
                this.Top += e.Y - OrgY;
            }
        }

        private void Control_MouseUp(object sender, MouseEventArgs e)
        {
            IsDrag = false;
        }

        private void lnbCancel_Click(object sender, EventArgs e)
        {
            if (Thd != null)
            {
                Thd.Abort();
                this.Close();
            }
        }
    }
}
